﻿<UserControl x:Class="ModernUILogViewer.Content.ContentColorSettings"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:model="clr-namespace:ModernUILogViewer.Model"
             xmlns:vm="clr-namespace:ModernUILogViewer.ViewModel"
             xmlns:view="clr-namespace:ModernUILogViewer.View"                
             xmlns:elements="clr-namespace:ModernUILogViewer.Elements"                
             xmlns:business="clr-namespace:ModernUILogViewer.Business"                          
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:helper="clr-namespace:ModernUILogViewer.Elements.Helpers"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"                
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"                
             mc:Ignorable="d"              
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"></ColumnDefinition>
            <ColumnDefinition Width="8*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <!--<DataGrid x:Name="dataGrid" ItemsSource="{Binding Source={StaticResource levels}}" AutoGenerateColumns="False" IsReadOnly="True" Margin="{StaticResource DefaultTopLeftMargin}">                        
                        <DataGrid.Columns>                            
                            <mui:DataGridTextColumn Binding="{Binding}"/>
                            <DataGridTemplateColumn>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border x:Name="brd" Width="10" Height="10" Style="{StaticResource borderStyle}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>-->

        <DataGrid x:Name="dataGrid" AutoGenerateColumns="False" IsReadOnly="True" Margin="{StaticResource DefaultTopLeftMargin}" Grid.Column="0" SelectedIndex="0">
            <DataGrid.Items>
                <elements:LogColor Level="NONE" BrushColor="{Binding Source={StaticResource colorsettings}, Path=NoneColor, TargetNullValue={StaticResource NONE_COLOR}, Mode=TwoWay}"  />
                <elements:LogColor Level="DEBUG" BrushColor="{Binding Source={StaticResource colorsettings}, Path=DebugColor, TargetNullValue={StaticResource DEBUG_COLOR}, Mode=TwoWay}"  />
                <elements:LogColor Level="INFO" BrushColor="{Binding Source={StaticResource colorsettings}, Path=InfoColor, TargetNullValue={StaticResource INFO_COLOR}, Mode=TwoWay}"  />
                <elements:LogColor Level="WARN" BrushColor="{Binding Source={StaticResource colorsettings}, Path=WarnColor, TargetNullValue={StaticResource WARN_COLOR}, Mode=TwoWay}"  />
                <elements:LogColor Level="ERROR" BrushColor="{Binding Source={StaticResource colorsettings}, Path=ErrorColor, TargetNullValue={StaticResource ERROR_COLOR}, Mode=TwoWay}"  />
                <elements:LogColor Level="FATAL" BrushColor="{Binding Source={StaticResource colorsettings}, Path=FatalColor, TargetNullValue={StaticResource FATAL_COLOR}, Mode=TwoWay}"  />
                <!--<elements:LogColor Level="WARN" BrushColor="{DynamicResource WARN_COLOR}"  />-->

            </DataGrid.Items>
            <DataGrid.Columns>
                <mui:DataGridTextColumn Binding="{Binding Level}"/>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Border Width="10" Height="10" Background="{Binding BrushColor}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

        <xctk:ColorCanvas                     
                    Grid.Column="1"
                    HorizontalAlignment="Left"
                    MaxWidth="400"
                    MaxHeight="300"
                    Margin="{StaticResource DefaultTopLeftMargin}"
                    x:Name="colorCanvas" 
                    VerticalAlignment="Top"
                    UsingAlphaChannel="False"                    
                    DataContext="{Binding ElementName=dataGrid, Path=SelectedItem}"
                    HexadecimalString="{Binding BrushColor, Mode=TwoWay}"
              
                    />

        <!--<Border Width="10" Height="10" Background="{DynamicResource prova}" />-->

        <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal" Grid.ColumnSpan="2" Grid.Row="1" Margin="{StaticResource DefaultTopLeftMargin}">
            <Button x:Name="savebtn" IsEnabled="False" Content="Save" Command="{Binding  Source={StaticResource settingsmanager}, Path=SaveSettings}" CommandParameter="{StaticResource colorsettings}" />
            <Button x:Name="reloadbtn" IsEnabled="False" Content="Reload" Command="{Binding Source={StaticResource settingsmanager}, Path=ReloadSettings}"  CommandParameter="{StaticResource colorsettings}" Margin="{StaticResource DefaultLeftMargin}" />
        </StackPanel>
        
    </Grid>
    
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding ElementName=colorCanvas, Path=HexadecimalString}">
            <ei:ChangePropertyAction TargetName="savebtn" PropertyName="IsEnabled" Value="True" />
            <ei:ChangePropertyAction TargetName="reloadbtn" PropertyName="IsEnabled" Value="True" />
        </ei:PropertyChangedTrigger>

        <i:EventTrigger EventName="SettingsSaved" SourceObject="{StaticResource settingsmanager}">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=savebtn}" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=reloadbtn}" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>
        <i:EventTrigger EventName="SettingsReloaded" SourceObject="{StaticResource settingsmanager}">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=reloadbtn}" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=savebtn}" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>

    </i:Interaction.Triggers>

</UserControl>
